//
//  ListenTestInfoView.m
//  xpkc
//
//  Created by wanmeizty iOS on 14-8-19.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "ListenTestInfoView.h"

@implementation ListenTestInfoView
{
	UILabel *nameLabel;
	UILabel *durationLabel;
	UILabel *startCountLabel;
	UIImageView *viewImageView;
	
	UIView *lineView1;
	UIView *btnBaseView;
	UIView *starBaseView;
}
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self createView2];
    }
    return self;
}
/**
 *  创建视图
 */
-(void)creatView{
    self.backgroundColor = [UIColor whiteColor];
    //创建控件
    self.videoImageView = [[UIImageView alloc]init];
    self.videoTitle = [[UILabel alloc]init];
	self.videoDuration = [[UILabel alloc]init];
    self.videoViewNum = [[UILabel alloc]init];
    self.videoTeacher = [[UILabel alloc]init];
    self.videoPubDate = [[UILabel alloc]init];
    self.videoClassName = [[UILabel alloc]init];
    self.videoPlayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UILabel *videoDurationLabel = [[UILabel alloc]init];
    UILabel *videoViewNumLabel = [[UILabel alloc]init];
    UILabel *videoTeacherLabel = [[UILabel alloc]init];
    UILabel *videoPubDateLabel = [[UILabel alloc]init];
    UILabel *videoClassLabel = [[UILabel alloc]init];
    //位置
    CGRect image_frame;
    CGRect title_frame;
    CGRect duration_label_frame,duration_frame;
    CGRect viewnum_label_frame,viewnum_frame;
    CGRect teacher_label_frame,teacher_frame;
    CGRect pubdate_label_frame,pubdate_frame;
    CGRect class_label_frame,class_frame;
    CGRect playbtn_frame;
    if (isPad) {
        //横排
        image_frame = CGRectMake(5, 5, 320, 240);
        title_frame = CGRectMake(330, 5, (SCREEN_WIDTH-340), 50);
        duration_label_frame = CGRectMake(330+20, 60, 40, 30);
        duration_frame = CGRectMake(330+20+40, 60, (SCREEN_WIDTH-330)/2-60, 30);
        viewnum_label_frame = CGRectMake(330+(SCREEN_WIDTH-330)/2+10, 60, 40, 30);
        viewnum_frame = CGRectMake(330+(SCREEN_WIDTH-330)/2+50, 60, (SCREEN_WIDTH-330)/2-50, 30);
        teacher_label_frame = CGRectMake(330+20, 100, 40, 30);
        teacher_frame = CGRectMake(330+20+40, 100, (SCREEN_WIDTH-330)/2-60, 30);
        pubdate_label_frame = CGRectMake(330+20, 140, 40, 30);
        pubdate_frame = CGRectMake(330+20+40, 140, (SCREEN_WIDTH-330)/2, 30);
        class_label_frame = CGRectMake(330+(SCREEN_WIDTH-330)/2+10, 100, 40, 30);
        class_frame = CGRectMake(330+(SCREEN_WIDTH-330)/2+50, 100, (SCREEN_WIDTH-330)/2, 30);
        playbtn_frame = CGRectMake(330+60, 190, SCREEN_WIDTH-330-120, 50);
    }else{
        if (SCREEN_HEIGHT>480) {
            image_frame = CGRectMake(5, 5, SCREEN_WIDTH-10, 205);
            title_frame = CGRectMake(0, 210, SCREEN_WIDTH, 40);
            duration_label_frame = CGRectMake(20, 250, 40, 30);
            duration_frame = CGRectMake(60, 250, SCREEN_WIDTH/2-60, 30);
            viewnum_label_frame = CGRectMake(SCREEN_WIDTH/2+10, 250, 40, 30);
            viewnum_frame = CGRectMake(SCREEN_WIDTH/2+50, 250, SCREEN_WIDTH/2-50, 30);
            teacher_label_frame = CGRectMake(20, 280, 40, 30);
            teacher_frame = CGRectMake(60, 280, SCREEN_WIDTH/2-60, 30);
            pubdate_label_frame = CGRectMake(20, 310, 40, 30);
            pubdate_frame = CGRectMake(60, 310, SCREEN_WIDTH/2, 30);
            class_label_frame = CGRectMake(20, 340, 40, 30);
            class_frame = CGRectMake(60, 340, SCREEN_WIDTH/2, 30);
            playbtn_frame = CGRectMake(60, 380, SCREEN_WIDTH-120, 40);
        }else{
            image_frame = CGRectMake(10, 2, 300, 180);
            title_frame = CGRectMake(10, 180, SCREEN_WIDTH-20, 40);
            duration_label_frame = CGRectMake(20, 220, 40, 30);
            duration_frame = CGRectMake(60, 220, SCREEN_WIDTH/2-60, 30);
            viewnum_label_frame = CGRectMake(SCREEN_WIDTH/2+10, 220, 40, 30);
            viewnum_frame = CGRectMake(SCREEN_WIDTH/2+50, 220, SCREEN_WIDTH/2-50, 30);
            teacher_label_frame = CGRectMake(20, 250, 40, 30);
            teacher_frame = CGRectMake(60, 250, SCREEN_WIDTH/2-60, 30);
            pubdate_label_frame = CGRectMake(20, 280, 40, 30);
            pubdate_frame = CGRectMake(60, 280, SCREEN_WIDTH/2, 30);
            class_label_frame = CGRectMake(20, 310, 40, 30);
            class_frame = CGRectMake(60, 310, SCREEN_WIDTH/2, 30);
            playbtn_frame = CGRectMake(60, 350, SCREEN_WIDTH-120, 40);
        }
        
    }
    self.videoImageView.frame = image_frame;
    self.videoTitle.frame = title_frame;
    videoDurationLabel.frame = duration_label_frame;
    self.videoDuration.frame = duration_frame;
    videoViewNumLabel.frame = viewnum_label_frame;
    self.videoViewNum.frame = viewnum_frame;
    videoTeacherLabel.frame = teacher_label_frame;
    self.videoTeacher.frame = teacher_frame;
    videoPubDateLabel.frame = pubdate_label_frame;
    self.videoPubDate.frame = pubdate_frame;
    videoClassLabel.frame=class_label_frame;
    self.videoClassName.frame=class_frame;
    self.videoPlayBtn.frame = playbtn_frame;
    //基本属性
    self.videoTitle.textAlignment = NSTextAlignmentCenter;
    self.videoTitle.font = FONT_BOLD(18);
    videoDurationLabel.font = FONT_SYS_NORMAL;
    self.videoDuration.font = FONT_SYS_NORMAL;
    videoViewNumLabel.font = FONT_SYS_NORMAL;
    self.videoViewNum.font = FONT_SYS_NORMAL;
    videoTeacherLabel.font = FONT_SYS_NORMAL;
    self.videoTeacher.font = FONT_SYS_NORMAL;
    videoClassLabel.font = FONT_SYS_NORMAL;
    self.videoClassName.font = FONT_SYS_NORMAL;
    videoPubDateLabel.font = FONT_SYS_NORMAL;
    self.videoPubDate.font = FONT_SYS_NORMAL;
    self.videoTitle.backgroundColor = RGBCOLOR(230, 230, 230);
    videoDurationLabel.textColor = [UIColor lightGrayColor];
    self.videoDuration.textColor = [UIColor lightGrayColor];
    videoViewNumLabel.textColor = [UIColor lightGrayColor];
    self.videoViewNum.textColor = [UIColor lightGrayColor];
    videoTeacherLabel.textColor = [UIColor lightGrayColor];
    self.videoTeacher.textColor = [UIColor orangeColor];
    videoPubDateLabel.textColor = [UIColor lightGrayColor];
    self.videoPubDate.textColor = [UIColor orangeColor];
    videoClassLabel.textColor = [UIColor lightGrayColor];
    self.videoClassName.textColor = GreenColor;
    self.videoPlayBtn.backgroundColor = [UIColor orangeColor];
    [self.videoPlayBtn setTitle:@"在线观看" forState:UIControlStateNormal];
    [self.videoPlayBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.videoPlayBtn setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    self.videoPlayBtn.titleLabel.shadowOffset = CGSizeMake(1, 0.5);
    self.videoPlayBtn.titleLabel.font = FONT_BOLD_BIG;
    self.videoPlayBtn.layer.cornerRadius = 5.0;
    videoDurationLabel.text = @"时长:";
    videoViewNumLabel.text = @"播放:";
    videoTeacherLabel.text = @"名师:";
    videoPubDateLabel.text = @"考试:";
    videoClassLabel.text = @"班次:";
    //添加
    [self addSubview:self.videoImageView];
    [self addSubview:self.videoTitle];
    [self addSubview:videoDurationLabel];
    [self addSubview:self.videoDuration];
    [self addSubview:videoViewNumLabel];
    [self addSubview:self.videoViewNum];
    [self addSubview:videoTeacherLabel];
    [self addSubview:self.videoTeacher];
    [self addSubview:videoPubDateLabel];
    [self addSubview:self.videoPubDate];
    [self addSubview:videoClassLabel];
    [self addSubview:self.videoClassName];
    [self addSubview:self.videoPlayBtn];
    
}
-(void)createView2
{
	self.backgroundColor = [UIColor whiteColor];
	//创建控件
	self.videoImageView = [[UIImageView alloc]init];
	self.videoTitle = [[UILabel alloc]init];
	self.videoDuration = [[UILabel alloc]init];
	self.videoViewNum = [[UILabel alloc]init];
	self.videoTeacher = [[UILabel alloc]init];
	self.videoPubDate = [[UILabel alloc]init];
	self.videoClassName = [[UILabel alloc]init];
	self.videoPlayBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	self.introduceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	self.commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	self.btnSliderView = [[UIView alloc]init];
	
	nameLabel = [[UILabel alloc]init];
	durationLabel = [[UILabel alloc]init];
	starBaseView = [[UIView alloc]init];
	startCountLabel = [[UILabel alloc]init];
	viewImageView = [[UIImageView alloc]init];
	_viewLabel = [[UILabel alloc]init];
	
	float videoIVWidth = SCREEN_WIDTH *0.516;
	float videoIVHeight = videoIVWidth * 0.558;
	float videoIVX = (SCREEN_WIDTH - videoIVWidth)/2.0;
	float videoIVy = 15;
	
	self.videoImageView.frame = CGRectMake(videoIVX, videoIVy, videoIVWidth, videoIVHeight);
	self.videoImageView.backgroundColor = [UIColor cyanColor];
	
	self.videoTitle.frame = CGRectMake(0, CGRectGetMaxY(self.videoImageView.frame), SCREEN_WIDTH, 30);
	self.videoTitle.textAlignment = NSTextAlignmentCenter;
	self.videoTitle.font = [UIFont systemFontOfSize:13];

	nameLabel.frame = CGRectMake(23, CGRectGetMaxY(self.videoTitle.frame) + 5, 100, 15);
	nameLabel.text = @"讲师:";
	nameLabel.font = [UIFont systemFontOfSize:13];
	

	self.videoTeacher.frame = CGRectMake(63, CGRectGetMaxY(self.videoTitle.frame) + 5, 100, 15);
	self.videoTeacher.font = [UIFont systemFontOfSize:13];
	
	durationLabel.frame = CGRectMake(145, CGRectGetMaxY(self.videoTitle.frame) + 5, 100, 15);
	durationLabel.text = @"时长：";
	durationLabel.font = [UIFont systemFontOfSize:13];
	
	self.videoDuration.frame = CGRectMake(185, CGRectGetMaxY(self.videoTitle.frame) + 5, 100, 15);
	self.videoDuration.font = [UIFont systemFontOfSize:13];
	
	
	/**
	 星星
	 */
	starBaseView.frame = CGRectMake(23, CGRectGetMaxY(self.videoDuration.frame) + 10, 55, 10);
	for (int i = 0; i<5; i++) {
		UIImageView *starImageView = [[UIImageView alloc]init];
		starImageView.frame = CGRectMake(12*i, 0, 10, 10);
		starImageView.image = [UIImage imageNamed:@"star_empty.png"];
		starImageView.tag = i+1;
		[starBaseView addSubview:starImageView];
	}
	startCountLabel.frame = CGRectMake(CGRectGetMaxX(starBaseView.frame)+5, CGRectGetMaxY(self.videoDuration.frame) + 10, 100, 10);
	startCountLabel.font = [UIFont systemFontOfSize:10];
//	startCountLabel.text = @"(280)";
	
	viewImageView.frame = CGRectMake(145, CGRectGetMaxY(self.videoDuration.frame) + 10, 10, 10);
	viewImageView.image = [UIImage imageNamed:@"tabbar-user.png"];
	
	_viewLabel.frame = CGRectMake(CGRectGetMaxX(viewImageView.frame)+ 5, CGRectGetMaxY(self.videoDuration.frame) + 10, 100, 10);
//	viewLabel.text = @"1890人观看";
	_viewLabel.font = [UIFont systemFontOfSize:10];
	
	lineView1 = [[UIView alloc]init];
	lineView1.frame = CGRectMake(0, CGRectGetMaxY(starBaseView.frame)+10, SCREEN_WIDTH, 1);
	lineView1.backgroundColor = [UIColor lightGrayColor];
	lineView1.alpha = 0.5;
	_lineView2 = [[UIView alloc]init];
	_lineView2.frame = CGRectMake(0, CGRectGetMaxY(starBaseView.frame) + 51, SCREEN_WIDTH, 1);
	_lineView2.alpha = 0.5;
	_lineView2.backgroundColor = [UIColor lightGrayColor];
	
	btnBaseView = [[UIView alloc]init];
	btnBaseView.frame = CGRectMake(0, CGRectGetMaxY(starBaseView.frame)+11, SCREEN_WIDTH, 40);
	btnBaseView.backgroundColor = [UIColor whiteColor];
	
	self.introduceBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH/2.0, 40);
	[self.introduceBtn setTitle:@"推荐课程" forState:UIControlStateNormal];
	self.introduceBtn.titleLabel.font = [UIFont systemFontOfSize:13];
	self.introduceBtn.tag = 1;
	[self.introduceBtn setTitleColor:[UIColor colorWithRed:4/255.0 green:175/255.0 blue:94/255.0 alpha:1] forState:UIControlStateSelected];
	[self.introduceBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
	self.introduceBtn.selected = YES;
	self.introduceBtn.transform = CGAffineTransformMakeScale(1.2, 1.2);
	
	self.commentBtn.frame = CGRectMake(SCREEN_WIDTH/2.0, 0, SCREEN_WIDTH/2.0, 40);
	[self.commentBtn setTitle:@"评价" forState:UIControlStateNormal];
	self.commentBtn.titleLabel.font = [UIFont systemFontOfSize:13];
	self.commentBtn.tag = 2;
	[self.commentBtn setTitleColor:[UIColor colorWithRed:4/255.0 green:175/255.0 blue:94/255.0 alpha:1] forState:UIControlStateSelected];
	[self.commentBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
	self.commentBtn.selected = NO;
	
	self.btnSliderView.frame = CGRectMake(0, 38, SCREEN_WIDTH/2, 2);
	self.btnSliderView.backgroundColor = [UIColor colorWithRed:4/255.0 green:175/255.0 blue:94/255.0 alpha:1];
	
	
	self.videoPlayBtn.frame = self.videoImageView.frame;
	[self.videoPlayBtn setImage:[UIImage imageNamed:@"listentest_selected@2x.png"] forState:UIControlStateNormal];
	
	[self addView];
}
-(void)addView
{
	[self addSubview:self.videoImageView];
	[self addSubview:self.videoTitle];
	[self addSubview:nameLabel];
	[self addSubview:self.videoTeacher];
	[self addSubview:durationLabel];
	[self addSubview:self.videoDuration];
	[self addSubview:starBaseView];
	[self addSubview:startCountLabel];
	[self addSubview:viewImageView];
	[self addSubview:_viewLabel];
	[self addSubview:lineView1];
	[self addSubview:_lineView2];
	[self addSubview:btnBaseView];
	[btnBaseView addSubview:self.introduceBtn];
	[btnBaseView addSubview:self.commentBtn];
	[btnBaseView addSubview:self.btnSliderView];
	[self addSubview:self.videoPlayBtn];
}
-(void)setStarImageViewWithNumber:(NSString *)numStr;
{
	CGFloat num = numStr.floatValue;
	int fullNum = (int)num;
	BOOL isHalf = (CGFloat)(num - fullNum)>0.1?YES:NO;
	for (UIImageView *starIV in starBaseView.subviews) {
		starIV.image = [UIImage imageNamed:@"star_empty.png"];
		if (starIV.tag<=fullNum) {
			starIV.image = [UIImage imageNamed:@"star_full.png"];
		}
		else if (starIV.tag == fullNum + 1 && isHalf) {
			starIV.image = [UIImage imageNamed:@"star_half.png"];
		}
	}
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
